package com.example.thegreatwall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.thegreatwall.common.R;
import com.example.thegreatwall.entity.Banner;
import com.example.thegreatwall.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin(origins = "*") //无论什么源都可以访问  不写这个不允许跨域
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;
    /**
     *  轮播图
     */
    @GetMapping(value = "bannerlist")
    public R bannerlist(){
        QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("banner_id").last("LIMIT 5");
        List<Banner> list = bannerService.list(queryWrapper);
        return new R().addDate("list",list);
    }
}
